package com.treeroot.planeservice.plane.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.treeroot.planeservice.plane.entity.PcPlaneConnecting;
import com.treeroot.planeservice.plane.mapper.PcPlaneConnectingMapper;
import com.treeroot.planeservice.plane.service.PcPlaneConnectingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author:treeRoot
 * @Email:553503639@qq.com
 * @Date: Create in 08:46 / 2022/6/6
 */
@Service
@Transactional
public class PcPlaneConnectingServiceImpl extends ServiceImpl<PcPlaneConnectingMapper, PcPlaneConnecting> implements PcPlaneConnectingService {
    /**
     * @param current 当前页
     * @param limit   最大页
     */


    @Override
    public Map getConnectingList(long current, long limit) {
        //  调用方法实现分页

        Page<PcPlaneConnecting> planePage = new Page<>(current, limit);
        //调用方法的时候，底层封装把分页所有数据封装到pagePlane对象里
        baseMapper.selectPage(planePage,null);
        List<PcPlaneConnecting> records = planePage.getRecords();
        long total = planePage.getTotal();
        Map map = new HashMap();
        map.put("total", total);
        map.put("rows", records);
        return map;

    }

    @Override
    public Map getQueryConnectingList(long current, long limit, PcPlaneConnecting plane) {
        Page<PcPlaneConnecting> connectingPage = new Page<>(current,limit);
//      构建条件
        LambdaQueryWrapper<PcPlaneConnecting> wrapper = new QueryWrapper<PcPlaneConnecting>().lambda()

                .eq(
                        !StringUtils.isEmpty(plane.getFlightNumber()),
                        PcPlaneConnecting::getFlightNumber,
                        plane.getFlightNumber()
                );

        //    调用方法实现查询
        baseMapper.selectPage(connectingPage, wrapper);
        long total = connectingPage.getTotal();
        List<PcPlaneConnecting> records = connectingPage.getRecords();//数据list集合
        Map map =new HashMap();
        map.put("total",total);
        map.put("rows",records);
        return map;
    }
}
